package svc

import (
	"github.com/go-redis/redis"
	"github.com/zeromicro/go-zero/zrpc"
	"server_1.0/api/internal/config"
	"server_1.0/service/admin/admincenter"
	"server_1.0/service/class/classcenter"
	"server_1.0/service/college/collegecenter"
	"server_1.0/service/major/majorcenter"
	"server_1.0/service/personality/personalitycenter"
	"server_1.0/service/question/questioncenter"
	"server_1.0/service/result/resultcenter"
	"server_1.0/service/student/studentcenter"
	"server_1.0/util"
)

type ServiceContext struct {
	Config config.Config

	AdminRpc       admincenter.AdminCenter
	CollegeRpc     collegecenter.CollegeCenter
	MajorRpc       majorcenter.MajorCenter
	ClassRpc       classcenter.ClassCenter
	StudentRpc     studentcenter.StudentCenter
	ResultRpc      resultcenter.ResultCenter
	PersonalityRpc personalitycenter.PersonalityCenter
	QuestionRpc    questioncenter.QuestionCenter

	Redis *redis.Client
}

func NewServiceContext(c config.Config) *ServiceContext {
	redis := util.NewRedis(c.Redis.Host, c.Redis.Password, c.Redis.Db)
	return &ServiceContext{
		Config:         c,
		AdminRpc:       admincenter.NewAdminCenter(zrpc.MustNewClient(c.AdminRpc)),
		CollegeRpc:     collegecenter.NewCollegeCenter(zrpc.MustNewClient(c.CollegeRpc)),
		MajorRpc:       majorcenter.NewMajorCenter(zrpc.MustNewClient(c.MajorRpc)),
		ClassRpc:       classcenter.NewClassCenter(zrpc.MustNewClient(c.ClassRpc)),
		StudentRpc:     studentcenter.NewStudentCenter(zrpc.MustNewClient(c.StudentRpc)),
		ResultRpc:      resultcenter.NewResultCenter(zrpc.MustNewClient(c.ResultRpc)),
		PersonalityRpc: personalitycenter.NewPersonalityCenter(zrpc.MustNewClient(c.PersonalityRpc)),
		QuestionRpc:    questioncenter.NewQuestionCenter(zrpc.MustNewClient(c.QuestionRpc)),
		Redis:          redis,
	}
}
